function SpriteAnimator(painters, elapsedCallback){
	this.painters = painters || [];
	this.elapsedCallback = elapsedCallback;
	this.duration = 1000;
	this.startTime = 0;
	this.index = 0;
}

SpriteAnimator.prototype = {
	start: function(sprite, duration){
		var endTime = +new Date() + duration,
			period = duration / (this.painters.length), // 周期
			animator = this,
			originalPainter = sprite.painter,
			lastUpdate = 0;

		this.index = 0;
		sprite.animating = true;
		sprite.painter = this.painters[this.index];

		requestNextAnimationFrame(function spriteAnimatorAnimate(time){
			time = +new Date();

			if(time < endTime){
				if((time - lastUpdate) > period){
					sprite.painter = animator.painters[++animator.index];
					lastUpdate = time;
				}
				requestNextAnimationFrame(spriteAnimatorAnimate);
			}else{
				animator.end(sprite, originalPainter);
			}
		});
	},

	end: function(sprite, originalPainter){
		sprite.animating = false;
		if(this.elapsedCallback){
			this.elapsedCallback(sprite);
		}else{
			sprite.painter = originalPainter;
		}
	}
};